package main

import (
	"fmt"
	"log"
	"rpc-demo/net"
	"time"
)

func main() {
	server := net.NexusServer[string]{
		Port: 8888,
		Sr:   "gob",
		Rhd: func(data string, chanel *net.NexusChanel[string], err error) {
			log.Println("接收到客户端消息 " + string(data))
			str := "hello client"
			chanel.Write(str)
		},
	}

	client := net.NexusClient[string]{
		Address: "127.0.0.1:8888",
		Sr:      "gob",
		Rhd: func(data string, chanel *net.NexusChanel[string], err error) {
			log.Println("接收到服务端消息 " + string(data))
		},
	}

	go server.StartServer()

	time.Sleep(time.Second * 1)
	go func() {
		for {
			var msg string
			fmt.Printf("输入消息：")
			fmt.Scan(&msg)
			client.SendMsg(msg)
			time.Sleep(time.Second * 1)
		}
	}()

	time.Sleep(10000 * time.Hour)
}
